<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>点击</button>
    <script>
        var that;
        class Student {
            constructor(uname) {
                that = this;
                //this指向实例化对象
                this.uname = uname;
                this.btn = document.querySelector('button');
                //this指向button
                this.btn.onclick = this.getUname;
            }
            getUname() {
                console.log(that.uname);
            }

        }
        var studetn = new Student("学生1");
        //1.在ES6中类没有变量提升，所以必须先定义类，才能通过类实例化对象
        //2.类中的共有属性和方法一定要加this
    </script>




</body>

</html>